<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>Document</title>
  </head>

  <body>
    <script>
      // 浅拷贝只是拷贝一层, 更深层次对象级别的只拷贝引用.
      // 深拷贝拷贝多层, 每一级别的数据都会拷贝.
      var obj = {
        id: 1,
        name: "andy",
        msg: {
          age: 18,
        },
      }
      var o = {}
      // for (var k in obj) {
      //     // k 是属性名   obj[k] 属性值
      //     o[k] = obj[k];
      // }
      // console.log(o);
      // o.msg.age = 20;
      // console.log(obj);

      console.log("--------------")
      Object.assign(o, obj)
      console.log(o)
      o.msg.age = 20
      console.log(obj)
    </script>
  </body>
</html>
